home
***
CD-ROM
|
disk
|
FTP
|
other
***
search
/
Almathera Ten Pack 2: CDPD 1
/
Almathera Ten on Ten - Disc 2: CDPD 1.iso
/
pd
/
076-100
/
087
/
elib
/
readme
< prev
next >
Wrap
Text File
|
1995-03-13
|
3KB
|
60 lines
Notes on Mylib: amiga exec library compatible with small model Aztec-C.
jimm mackraz -- october 28, 1986
[Apr 24, 1987:
the archive includes a file 'elib' which must be copied to
'LIBS:mylib.library' before the test program will run.]
Most of the work here is because Aztec uses d2, d3 (and others, according
to the manual) as scratch registers. This means that crt0.asm (the
C startup code) can't be called as is by OpenLibrary(), so an AutoInit
(RomTag) approach is used.
Note also that all entry points to the library must save and restore
registers (unless you can be sure that they won't be trashed).
Note also that arguments are passed to the library in registers, even
though this entails yanking them off the stack first and pushing them
back on later (and the compiler probably just puts them back into
registers itself). This is the Amiga convention, done so that
assembler applications calling assembler library functions are optimized,
and to be compiler/linker independent. We strongly recommend the
continuation of this practice. If you want better performance, write
the library functions in assembler, and take the arguments from registers
directly.
The example here consists of several files, some linked together to
create the library, some to create the example calling program (see
also the makefile).
Library:
elib.c -- c-code for initialization and library functions
rtag.asm -- data structure (but in code segment) for romtag
funky.asm -- modified aztec crt0.asm. saves registers, sets
up A4 (and for geta4()) calls my Init routine, restores.
libface.asm -- entry points for library functions: each saves
registers, sets up A4, pushes arguments on stack, calls
C-routine, fixes stack, restores regs.
Calling Program:
t.c -- opens library, calls its functions, closes library
liblink.asm -- interface for C calls to library calls. Note that
the symbol libbase in t.c must be named exactly that.
To add a new function written in C to this library, one must:
-write the C-code for the function
-write the library side interface routine in libface.asm
-write the C application side interface in liblink.asm
Note the simplicity afforded by declaring all integer parameters
and return values as LONG.
To add a new function written in assembler, you needn't do a library
side interface which pushes arguments on the stack, nor need you save
more registers than you are explicity using. Note, though, that
a4 must be setup using geta4() (save it first!) to do any small model
references, and calling any Aztec function might require that you
save registers.